package com.webonn.frame.util;

import org.apache.commons.codec.digest.DigestUtils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

/**
 * Created by Administrator on 2016/11/19.
 */
public class IdGenerator {
    public static DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");

    public static String generateUUID(String pre){
        String uuid = UUID.randomUUID().toString().replace("-","");
        return MyStringUtil.isNullOrEmpty(pre.trim()) ? uuid : pre + "_" + uuid;
    }

    public static String generateMd5Id(String pre, String content){
        String md5 = DigestUtils.md5Hex(content).toLowerCase();
        return MyStringUtil.isNullOrEmpty(pre.trim()) ? md5 : pre + "_" + md5;
    }

    public static String generateDateTimeId(String pre, Date date){
        String dateStr = dateFormat.format(date);
        return MyStringUtil.isNullOrEmpty(pre.trim()) ? dateStr : pre + "_" + dateStr;
    }

    public static String     generateTimeStampId(String pre, Date date){
        String dateStr = date.getTime()+"";
        return MyStringUtil.isNullOrEmpty(pre.trim()) ? dateStr : pre + "_" + dateStr;
    }
}
